<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=divice-width,initial-scale=1.0">
	<title>数组map</title>
</head>
<body>
	<script type="text/javascript">
		//map方法可以将原数组中的所有元素通过一个函数进行处理并放入一个新数组中然后返回该新数组
		//对arr数组中每个元素*2
		let arr = [1,2,3,4,5,6,7];
		//传统方式
		let new_arr = [];
		for(let i=0; i < arr.length; i++){
			new_arr.push(arr[i] * 2)
		}
		console.log(new_arr);
		//map  -- 自带循环， 并且会把处理的值回填到对应的位置
		let new_arr2 = arr.map(function(ele){
			return ele * 2;
		});
		console.log(new_arr2);
		//简化
		let new_arr3 = arr.map(ele=>ele * 2);
		console.log(new_arr3);

		//举个栗子
		let users = [{age:10,name:"小明"},{age:11,name:"大明"},{age:12,name:"小小"}];
		let new_users = users.map((ele)=>ele.age + 2);
		console.log(new_users);
	</script>
</body>
</html>